package cn.quizs.web.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

// 注解标注此类为springmvc的controller，url映射为"/home"
@Controller
@RequestMapping("/home")
public class ApiController {
    //添加一个日志器
    private static final Logger logger = LoggerFactory.getLogger(ApiController.class);

    //映射一个action
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        System.out.println("why is ");
        //输出日志文件
        logger.info("the first jsp pages");
        //返回一个index.jsp这个视图
        return "index";
    }


    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getProvicenAndCity(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> map = new HashMap<>();

        map.put("gan",1);
        map.put("sheng","test");
        return map;
    }

}

